package leetcode

import (
	"math/rand"
	"time"
)

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
type Solution struct {
	store []int
}


func Constructor(head *ListNode) Solution {
	s:=Solution{store: make([]int,0)}
	for head!=nil{
		s.store=append(s.store, head.Val)
		head=head.Next
	}
	return s
}


func (this *Solution) GetRandom() int {
	rand.Seed(time.Now().Unix()) // unix 时间戳，秒
	data := rand.Intn(len(this.store))
	return this.store[data]
}


/**
 * Your Solution object will be instantiated and called as such:
 * obj := Constructor(head);
 * param_1 := obj.GetRandom();
 */
